(* This file is part of IsoType.
 *
 * IsoType is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * IsoType is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with IsoType.  If not, see <http://www.gnu.org/licenses/>.
 *)

type t =
    { debug : bool ref;
      verbose : bool ref;
      show_differences : bool ref;
      focus_on : bool ref;
      distance : string ref;
      ignore_modules: string list ref; 
    }

let debug flags = !(flags.debug)
let verbose flags = !(flags.verbose)
let show_differences flags = !(flags.show_differences)
let focus_on flags = !(flags.focus_on)
let distance flags = !(flags.distance)
let ignore_modules flags = !(flags.ignore_modules)


let parse_arguments () =
  let usage_msg = "\
Usage: " ^ Filename.basename Sys.executable_name ^ " OPTIONS <interface> ...\n\
  <dist> is one of [" ^ String.concat "," Distance.names ^ "]\
"
  in
  let ifaces = ref [] in
  let add_interface name =
    ifaces := name :: !ifaces
  in
 let flags =
    { debug = ref false;
      verbose = ref false;
      show_differences = ref false;
      focus_on = ref false;
      distance = ref "Soergel";
      ignore_modules = ref [];
    }
 in 
 let ignore_module r s =
   r := s :: !r
 in
   Arg.parse
     [ "--debug", Arg.Set flags.debug, " Show debugging information";
       "--distance", Arg.Set_string flags.distance, "<dist> Distance function (default=Soergel)";
       "-d", Arg.Set_string flags.distance, "<dist> Distance function (default=Soergel)";
      "--ignore-module", Arg.String (ignore_module flags.ignore_modules), "<path> Ignore modules with the specifed path";
      "--focus", Arg.Set flags.focus_on, " Focus equivalence on one interface";
      "-f", Arg.Set flags.focus_on, " Focus equivalence on one interface";
      "--show", Arg.Set flags.show_differences, " Show differences between interfaces";
      "-V", Arg.Set flags.verbose, " Show statistics (on stderr)";
     ]
     add_interface usage_msg;
   Array.of_list (List.rev !ifaces), flags
     
